/**
 * 
 */
package com.nari.heatshare.service;

import com.nari.coreframe.service.GenericServiceImpl;
import com.nari.heatshare.dao.IHeatMeterTypeParamDictDao;
import com.nari.heatshare.model.IHeatMeterTypeParamDict;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.ResponseMsg;
import com.nari.platform.model.ResultWithPageCond;

/**
 * 
 * @author Xiaopeng
 * @date 2014-6-23
 */
public class HeatMeterTypeParamDictServiceImpl extends GenericServiceImpl<IHeatMeterTypeParamDict, String> 
		implements IHeatMeterTypeParamDictService {

	/**
	 * 分页查询热表型号参数配置列表
	 * @param typeCode 热量表型号编号
	 * @param pageCond
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public ResultWithPageCond<IHeatMeterTypeParamDict> queryTypeParamPage(String typeCode, 
			PageCond pageCond) throws Exception {
		IHeatMeterTypeParamDictDao iHeatMeterTypeParamDictDao = (IHeatMeterTypeParamDictDao) this.getiGenericDao();
		return iHeatMeterTypeParamDictDao.queryTypeParamPage(typeCode, pageCond);
	}
	
	/**
	 * 新增或修改型号参数配置
	 * @param typeParam
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public ResponseMsg saveOrUpdateTypeParamDict(IHeatMeterTypeParamDict typeParam) throws Exception {
		IHeatMeterTypeParamDictDao iHeatMeterTypeParamDictDao = (IHeatMeterTypeParamDictDao) this.getiGenericDao();
		//避免重复配置的型号编号
		int counter = iHeatMeterTypeParamDictDao.countTypeParamByTypeCode(typeParam.getTypeCode(), typeParam.getId());
		if(counter > 0) {
			return ResponseMsg.getInstance(false, "重复的型号编号，操作失败！");
		}
		//型号参数配置维护
		if(typeParam.getId()!=null && !"".equals(typeParam.getId())) {
			iHeatMeterTypeParamDictDao.updateEntity(typeParam, typeParam.getId());
		} else {
			iHeatMeterTypeParamDictDao.saveEntity(typeParam);
		}
		return ResponseMsg.getInstance(true, "");
	}
	
	/**
	 * 通过热量表型号编号查询其型号参数配置
	 * @param typeCode
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-24
	 */
	public IHeatMeterTypeParamDict queryTypeParamByCode(String typeCode) throws Exception {
		IHeatMeterTypeParamDictDao iHeatMeterTypeParamDictDao = (IHeatMeterTypeParamDictDao) this.getiGenericDao();
		return iHeatMeterTypeParamDictDao.queryTypeParamByCode(typeCode);
	}
	
	/**
	 * 根据型号编号统计型号参数的配置个数
	 * @param typeCode
	 * @param typeParamUID
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2014-6-23
	 */
	public int countTypeParamByTypeCode(String typeCode, String typeParamUID) throws Exception {
		IHeatMeterTypeParamDictDao iHeatMeterTypeParamDictDao = (IHeatMeterTypeParamDictDao) this.getiGenericDao();
		return iHeatMeterTypeParamDictDao.countTypeParamByTypeCode(typeCode, typeParamUID);
	}
}
